package cn.wzut.edut.dao.inf;

import cn.wzut.edut.dao.SnowflakeIdWorker;
import cn.wzut.edut.dao.mapper.ExmExamMapper;
import cn.wzut.edut.dao.mapper.ExmLibItemAnswerMapper;
import cn.wzut.edut.dao.mapper.ExmLibItemMapper;
import cn.wzut.edut.dao.mapper.ExmLibMapper;
import cn.wzut.edut.dao.pojo.table.ExmLib;
import cn.wzut.edut.dao.pojo.table.ExmLibItem;
import cn.wzut.edut.dao.pojo.table.ExmLibItemAnswer;
import cn.wzut.edut.dao.pojo.table.SysMenu;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.LinkedList;
import java.util.List;

/**
 * 题目功能管理
 */
@Repository
public class Lib {
    @Autowired
    private ExmLibMapper exmLibMapper;
    @Autowired
    private ExmLibItemMapper exmLibItemMapper;
    @Autowired
    private ExmLibItemAnswerMapper exmLibItemAnswerMapper;
    /**
     * ===================================================================================================
     * 基础查询
     * ===================================================================================================
     */
    /**
     * 查询题库信息
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public List<ExmLib> selectExmLib(String id, String createId, String libName, String deptId, String delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libName),"lib_name",libName);
        queryWrapper.in(!StringUtils.isEmpty(deptId),"dept_id",deptId);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 查询题库信息
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public List<ExmLib> selectExmLibPage(String id, String createId, String libName, String deptId, String delFlag,long current,long size){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libName),"lib_name",libName);
        queryWrapper.in(!StringUtils.isEmpty(deptId),"dept_id",deptId);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibMapper.selectPage(new Page<ExmLib>(current,size),queryWrapper).getRecords();
    }
    /**
     * 列表
     * 查询题库信息
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public List<ExmLib> selectExmLibList(List<String> id, List<String> createId, List<String> libName, List<String> deptId, List<String> delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libName!=null,"lib_name",libName);
        queryWrapper.in(deptId!=null,"dept_id",deptId);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 列表
     * 查询题库信息
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public List<ExmLib> selectExmLibListPage(List<String> id, List<String> createId, List<String> libName, List<String> deptId, List<String> delFlag,long current,long size){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libName!=null,"lib_name",libName);
        queryWrapper.in(deptId!=null,"dept_id",deptId);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibMapper.selectPage(new Page<ExmLib>(current,size),queryWrapper).getRecords();
    }
    /**
     * 查询题库信息数量
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public long countExmLib(String id, String createId, String libName, String deptId, String delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libName),"lib_name",libName);
        queryWrapper.in(!StringUtils.isEmpty(deptId),"dept_id",deptId);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibMapper.selectCount(queryWrapper);
    }
    /**
     * 列表
     * 查询题库信息数量
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public long countExmLibList(List<String> id, List<String> createId, List<String> libName, List<String> deptId, List<String> delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libName!=null,"lib_name",libName);
        queryWrapper.in(deptId!=null,"dept_id",deptId);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibMapper.selectCount(queryWrapper);
    }


    /**
     * 查询题目信息
     */
    public List<ExmLibItem> selectExmLibItem(String id,String itemType,String refGrade,String itemContent,String option,String itemAnalysis,String itemFlag,String createId,String libId,String itemCode, String version,String delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(itemType),"item_type",itemType);
        queryWrapper.in(!StringUtils.isEmpty(refGrade),"ref_grade",refGrade);
        queryWrapper.in(!StringUtils.isEmpty(itemContent),"item_content",itemContent);
        queryWrapper.in(!StringUtils.isEmpty(option),"option",option);
        queryWrapper.in(!StringUtils.isEmpty(itemAnalysis),"item_analysis",itemAnalysis);
        queryWrapper.in(!StringUtils.isEmpty(itemFlag),"item_flag",itemFlag);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libId),"lib_id",libId);
        queryWrapper.in(!StringUtils.isEmpty(itemCode),"item_code",itemCode);
        queryWrapper.in(!StringUtils.isEmpty(version),"version",version);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibItemMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 查询题目信息
     */
    public List<ExmLibItem> selectExmLibItemPage(String id,String itemType,String refGrade,String itemContent,String option,String itemAnalysis,String itemFlag,String createId,String libId,String itemCode, String version,String delFlag,long current,long size){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(itemType),"item_type",itemType);
        queryWrapper.in(!StringUtils.isEmpty(refGrade),"ref_grade",refGrade);
        queryWrapper.in(!StringUtils.isEmpty(itemContent),"item_content",itemContent);
        queryWrapper.in(!StringUtils.isEmpty(option),"option",option);
        queryWrapper.in(!StringUtils.isEmpty(itemAnalysis),"item_analysis",itemAnalysis);
        queryWrapper.in(!StringUtils.isEmpty(itemFlag),"item_flag",itemFlag);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libId),"lib_id",libId);
        queryWrapper.in(!StringUtils.isEmpty(itemCode),"item_code",itemCode);
        queryWrapper.in(!StringUtils.isEmpty(version),"version",version);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibItemMapper.selectPage(new Page<ExmLibItem>(current,size),queryWrapper).getRecords();
    }
    /**
     * 列表
     * 查询题目信息
     */
    public List<ExmLibItem> selectExmLibItemList(List<String> id,List<String> itemType,List<String> refGrade,List<String> itemContent,List<String> option,List<String> itemAnalysis,List<String> itemFlag,List<String> createId,List<String> libId,List<String> itemCode, List<String> version,List<String> delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(itemType!=null,"item_type",itemType);
        queryWrapper.in(refGrade!=null,"ref_grade",refGrade);
        queryWrapper.in(itemContent!=null,"item_content",itemContent);
        queryWrapper.in(option!=null,"option",option);
        queryWrapper.in(itemAnalysis!=null,"item_analysis",itemAnalysis);
        queryWrapper.in(itemFlag!=null,"item_flag",itemFlag);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libId!=null,"lib_id",libId);
        queryWrapper.in(itemCode!=null,"item_code",itemCode);
        queryWrapper.in(version!=null,"version",version);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibItemMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 列表
     * 查询题目信息
     */
    public List<ExmLibItem> selectExmLibItemListPage(List<String> id,List<String> itemType,List<String> refGrade,List<String> itemContent,List<String> option,List<String> itemAnalysis,List<String> itemFlag,List<String> createId,List<String> libId,List<String> itemCode, List<String> version,List<String> delFlag,long current,long size){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(itemType!=null,"item_type",itemType);
        queryWrapper.in(refGrade!=null,"ref_grade",refGrade);
        queryWrapper.in(itemContent!=null,"item_content",itemContent);
        queryWrapper.in(option!=null,"option",option);
        queryWrapper.in(itemAnalysis!=null,"item_analysis",itemAnalysis);
        queryWrapper.in(itemFlag!=null,"item_flag",itemFlag);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libId!=null,"lib_id",libId);
        queryWrapper.in(itemCode!=null,"item_code",itemCode);
        queryWrapper.in(version!=null,"version",version);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibItemMapper.selectPage(new Page<ExmLibItem>(current,size),queryWrapper).getRecords();
    }
    /**
     * 查询题目信息数量
     */
    public long countExmLibItem(String id,String itemType,String refGrade,String itemContent,String option,String itemAnalysis,String itemFlag,String createId,String libId,String itemCode, String version,String delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(itemType),"item_type",itemType);
        queryWrapper.in(!StringUtils.isEmpty(refGrade),"ref_grade",refGrade);
        queryWrapper.in(!StringUtils.isEmpty(itemContent),"item_content",itemContent);
        queryWrapper.in(!StringUtils.isEmpty(option),"option",option);
        queryWrapper.in(!StringUtils.isEmpty(itemAnalysis),"item_analysis",itemAnalysis);
        queryWrapper.in(!StringUtils.isEmpty(itemFlag),"item_flag",itemFlag);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libId),"lib_id",libId);
        queryWrapper.in(!StringUtils.isEmpty(itemCode),"item_code",itemCode);
        queryWrapper.in(!StringUtils.isEmpty(version),"version",version);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        return exmLibItemMapper.selectCount(queryWrapper);
    }
    /**
     * 列表
     * 查询题目信息数量
     */
    public long countExmLibItemList(List<String> id,List<String> itemType,List<String> refGrade,List<String> itemContent,List<String> option,List<String> itemAnalysis,List<String> itemFlag,List<String> createId,List<String> libId,List<String> itemCode, List<String> version,List<String> delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(itemType!=null,"item_type",itemType);
        queryWrapper.in(refGrade!=null,"ref_grade",refGrade);
        queryWrapper.in(itemContent!=null,"item_content",itemContent);
        queryWrapper.in(option!=null,"option",option);
        queryWrapper.in(itemAnalysis!=null,"item_analysis",itemAnalysis);
        queryWrapper.in(itemFlag!=null,"item_flag",itemFlag);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libId!=null,"lib_id",libId);
        queryWrapper.in(itemCode!=null,"item_code",itemCode);
        queryWrapper.in(version!=null,"version",version);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        return exmLibItemMapper.selectCount(queryWrapper);
    }



    /**
     * 查询答案信息
     */
    public List<ExmLibItemAnswer> selectExmLibItemAnswer(String id, String answer, String itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(answer),"answer",answer);
        queryWrapper.in(!StringUtils.isEmpty(itemId),"item_id",itemId);
        return exmLibItemAnswerMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 查询答案信息
     */
    public List<ExmLibItemAnswer> selectExmLibItemAnswerPage(String id, String answer, String itemId,long current,long size){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(answer),"answer",answer);
        queryWrapper.in(!StringUtils.isEmpty(itemId),"item_id",itemId);
        return exmLibItemAnswerMapper.selectPage(new Page<ExmLibItemAnswer>(current,size),queryWrapper).getRecords();
    }
    /**
     * 列表
     * 查询答案信息
     */
    public List<ExmLibItemAnswer> selectExmLibItemAnswerList(List<String> id,List<String> answer, List<String> itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(answer!=null,"answer",answer);
        queryWrapper.in(itemId!=null,"item_id",itemId);
        return exmLibItemAnswerMapper.selectList(queryWrapper);
    }
    /**
     * 分页
     * 列表
     * 查询答案信息
     */
    public List<ExmLibItemAnswer> selectExmLibItemAnswerListPage(List<String> id,List<String> answer, List<String> itemId,long current,long size){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(answer!=null,"answer",answer);
        queryWrapper.in(itemId!=null,"item_id",itemId);
        return exmLibItemAnswerMapper.selectPage(new Page<ExmLibItemAnswer>(current,size),queryWrapper).getRecords();
    }
    /**
     * 查询答案信息数量
     */
    public long countExmLibItemAnswer(String id, String answer, String itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(answer),"answer",answer);
        queryWrapper.in(!StringUtils.isEmpty(itemId),"item_id",itemId);
        return exmLibItemAnswerMapper.selectCount(queryWrapper);
    }
    /**
     * 列表
     * 查询答案信息数量
     */
    public long countExmLibItemAnswerList(List<String> id,List<String> answer, List<String> itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(answer!=null,"answer",answer);
        queryWrapper.in(itemId!=null,"item_id",itemId);
        return exmLibItemAnswerMapper.selectCount(queryWrapper);
    }
    /**
     * ===================================================================================================
     * 基础删除
     * ===================================================================================================
     */
    /**
     * 删除题库
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public boolean delExmLib(String id, String createId, String libName, String deptId, String delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libName),"lib_name",libName);
        queryWrapper.in(!StringUtils.isEmpty(deptId),"dept_id",deptId);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        exmLibMapper.delete(queryWrapper);
        return true;
    }
    /**
     * 列表
     * 删除题库
     * @param id
     * @param createId
     * @param libName
     * @param deptId
     * @param delFlag
     * @return
     */
    public boolean delExmLibList(List<String> id, List<String> createId, List<String> libName, List<String> deptId, List<String> delFlag){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libName!=null,"lib_name",libName);
        queryWrapper.in(deptId!=null,"dept_id",deptId);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        exmLibMapper.delete(queryWrapper);
        return true;
    }
    /**
     * 逻辑删除题库
     * true:不删除
     * flase：删除
     */
    public boolean logicDelLib(String id,boolean b){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        if(b){
            updateWrapper.set("del_flag","1");
        }else {
            updateWrapper.set("del_flag","0");
        }
        exmLibMapper.update(null,updateWrapper);
        return true;
    }
    /**
     * 列表
     * 逻辑删除题库
     * true:不删除
     * flase：删除
     */
    public boolean logicDelLibList(List<String> id,boolean b){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        if(b){
            updateWrapper.set("del_flag","1");
        }else {
            updateWrapper.set("del_flag","0");
        }
        exmLibMapper.update(null,updateWrapper);
        return true;
    }
    /**
     * 删除题目信息
     */
    public boolean delExmLibItem(String id,String itemType,String refGrade,String itemContent,String option,String itemAnalysis,String itemFlag,String createId,String libId,String itemCode, String version,String delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(itemType),"item_type",itemType);
        queryWrapper.in(!StringUtils.isEmpty(refGrade),"ref_grade",refGrade);
        queryWrapper.in(!StringUtils.isEmpty(itemContent),"item_content",itemContent);
        queryWrapper.in(!StringUtils.isEmpty(option),"option",option);
        queryWrapper.in(!StringUtils.isEmpty(itemAnalysis),"item_analysis",itemAnalysis);
        queryWrapper.in(!StringUtils.isEmpty(itemFlag),"item_flag",itemFlag);
        queryWrapper.in(!StringUtils.isEmpty(createId),"create_id",createId);
        queryWrapper.in(!StringUtils.isEmpty(libId),"lib_id",libId);
        queryWrapper.in(!StringUtils.isEmpty(itemCode),"item_code",itemCode);
        queryWrapper.in(!StringUtils.isEmpty(version),"version",version);
        queryWrapper.in(!StringUtils.isEmpty(delFlag),"del_flag",delFlag);
        exmLibItemMapper.delete(queryWrapper);
        return true;
    }
    /**
     * 删除题目信息
     */
    public boolean delExmLibItemList(List<String> id,List<String> itemType,List<String> refGrade,List<String> itemContent,List<String> option,List<String> itemAnalysis,List<String> itemFlag,List<String> createId,List<String> libId,List<String> itemCode, List<String> version,List<String> delFlag){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(itemType!=null,"item_type",itemType);
        queryWrapper.in(refGrade!=null,"ref_grade",refGrade);
        queryWrapper.in(itemContent!=null,"item_content",itemContent);
        queryWrapper.in(option!=null,"option",option);
        queryWrapper.in(itemAnalysis!=null,"item_analysis",itemAnalysis);
        queryWrapper.in(itemFlag!=null,"item_flag",itemFlag);
        queryWrapper.in(createId!=null,"create_id",createId);
        queryWrapper.in(libId!=null,"lib_id",libId);
        queryWrapper.in(itemCode!=null,"item_code",itemCode);
        queryWrapper.in(version!=null,"version",version);
        queryWrapper.in(delFlag!=null,"del_flag",delFlag);
        exmLibItemMapper.delete(queryWrapper);
        return true;
    }
    /**
     * 逻辑删除题目
     * true:不删除
     * flase：删除
     */
    public boolean logicDelLibExam(String id,boolean b){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        if(b){
            updateWrapper.set("del_flag","1");
        }else {
            updateWrapper.set("del_flag","0");
        }
        exmLibItemMapper.update(null,updateWrapper);
        return true;
    }
    /**
     * 列表
     * 逻辑删除题目
     * true:不删除
     * flase：删除
     */
    public boolean logicDelLibExamList(List<String> id,boolean b){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("id",id);
        if(b){
            updateWrapper.set("del_flag","1");
        }else {
            updateWrapper.set("del_flag","0");
        }
        exmLibItemMapper.update(null,updateWrapper);
        return true;
    }
    /**
     * 查询答案信息数量
     */
    public boolean delExmLibItemAnswer(String id, String answer, String itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(!StringUtils.isEmpty(id),"id",id);
        queryWrapper.in(!StringUtils.isEmpty(answer),"answer",answer);
        queryWrapper.in(!StringUtils.isEmpty(itemId),"item_id",itemId);
        exmLibItemAnswerMapper.delete(queryWrapper);
        return true;
    }
    /**
     * 列表
     * 查询答案信息数量
     */
    public boolean delExmLibItemAnswerList(List<String> id,List<String> answer, List<String> itemId){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(id!=null,"id",id);
        queryWrapper.in(answer!=null,"answer",answer);
        queryWrapper.in(itemId!=null,"item_id",itemId);
        exmLibItemAnswerMapper.delete(queryWrapper);
        return true;
    }

    /**
     * ===================================================================================================
     * 基础更新
     * ===================================================================================================
     */
    /**
     * 更新题库
     * @param exmLib
     * @return
     */
    public boolean updateExmLib(ExmLib exmLib){
        QueryWrapper<ExmLib> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",exmLib.getId());
        exmLibMapper.update(exmLib,queryWrapper);
        return true;
    }

    /**
     * 更新题目
     * @param exmLibItem
     * @return
     */
    public boolean updateExmLibItem(ExmLibItem exmLibItem){
        QueryWrapper<ExmLibItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",exmLibItem.getId());
        exmLibItemMapper.update(exmLibItem,queryWrapper);
        return true;
    }

    /**
     * 更新答案
     * @param exmLibItemAnswer
     * @return
     */
    public boolean updateExmLibItemAnswer(ExmLibItemAnswer exmLibItemAnswer){
        QueryWrapper<ExmLibItemAnswer> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",exmLibItemAnswer.getId());
        exmLibItemAnswerMapper.update(exmLibItemAnswer,queryWrapper);
        return true;
    }
    /**
     * ===================================================================================================
     * 基础新增
     * ===================================================================================================
     */
    /**
     * 新增题库
     * @param exmLib
     * @return
     */
    public boolean insertExmLib(ExmLib exmLib){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        exmLib.setId(String.valueOf(snowflakeIdWorker.nextId()));
        exmLibMapper.insert(exmLib);
        return true;
    }

    /**
     * 新增题目
     * @param exmLibItem
     * @return
     */
    public boolean insertExmLibItem(ExmLibItem exmLibItem){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        exmLibItem.setId(String.valueOf(snowflakeIdWorker.nextId()));
        exmLibItemMapper.insert(exmLibItem);
        return true;
    }

    /**
     * 新增答案
     * @param exmLibItemAnswer
     * @return
     */
    public boolean insertExmLibItemAnswer(ExmLibItemAnswer exmLibItemAnswer){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        exmLibItemAnswer.setId(String.valueOf(snowflakeIdWorker.nextId()));
        exmLibItemAnswerMapper.insert(exmLibItemAnswer);
        return true;
    }
    /**
     * 批量
     * 新增题库
     * @param exmLib
     * @return
     */
    public int insertExmLibList(List<ExmLib> exmLib){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        for (int i=0;i<exmLib.size();i++){
            exmLib.get(i).setId(String.valueOf(snowflakeIdWorker.nextId()));}
        return exmLibMapper.insertBatchSomeColumn(exmLib);
    }

    /**
     * 批量
     * 新增题目
     * @param exmLibItem
     * @return
     */
    public int insertExmLibItemList(List<ExmLibItem> exmLibItem){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        for (int i=0;i<exmLibItem.size();i++){
            exmLibItem.get(i).setId(String.valueOf(snowflakeIdWorker.nextId()));}
        return exmLibItemMapper.insertBatchSomeColumn(exmLibItem);
    }

    /**
     * 批量
     * 新增答案
     * @param exmLibItemAnswer
     * @return
     */
    public int insertExmLibItemAnswerList(List<ExmLibItemAnswer> exmLibItemAnswer){
        SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker();
        for (int i=0;i<exmLibItemAnswer.size();i++){
            exmLibItemAnswer.get(i).setId(String.valueOf(snowflakeIdWorker.nextId()));}
        return exmLibItemAnswerMapper.insertBatchSomeColumn(exmLibItemAnswer);
    }
    /**
     * ===================================================================================================
     * 级联删除
     * ===================================================================================================
     */
    /**
     * 级联删除题目
     */
    public boolean delCascadeLibItemByItemId(String item_id){
        delExmLibItemAnswer(null,null,item_id);
        delExmLibItem(item_id,null,null,null,null,null,null,null,null,null,null,null);
        return true;
    }

    /**
     * 列表
     * 级联删除题目
     */
    public boolean delCascadeLibItemByItemIdList(List<String> item_id){
        delExmLibItemAnswerList(null,null,item_id);
        delExmLibItemList(item_id,null,null,null,null,null,null,null,null,null,null,null);
        return true;
    }
    /**
     * 级联删除题库
     */
    public boolean delCascadeLib(String lib_id){
        List<ExmLibItem> exmLibItems = selectExmLibItem(null,null,null,null,null,null,null,null,lib_id,null,null,null);
        List<String> list = new LinkedList<>();
        for (int i = 0;i<exmLibItems.size();i++){
            list.add(exmLibItems.get(i).getId());
        }
        delExmLibItemAnswerList(null,null,list);
        delExmLibItem(null,null,null,null,null,null,null,null,lib_id,null,null,null);
        delExmLib(lib_id,null,null,null,null);
        return true;
    }
    /**
     * 列表
     * 级联删除题库
     */
    public boolean delCascadeLibList(List<String> lib_id){
        List<ExmLibItem> exmLibItems = selectExmLibItemList(null,null,null,null,null,null,null,null,lib_id,null,null,null);
        List<String> list = new LinkedList<>();
        for (int i = 0;i<exmLibItems.size();i++){
            list.add(exmLibItems.get(i).getId());
        }
        delExmLibItemAnswerList(null,null,list);
        delExmLibItemList(null,null,null,null,null,null,null,null,lib_id,null,null,null);
        delExmLibList(lib_id,null,null,null,null);
        return true;
    }
    /**
     * ===================================================================================================
     * 复杂查询
     * ===================================================================================================
     */
}
